﻿using System;
using System.IO;
using System.IO.IsolatedStorage;
using System.Net;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml;

namespace TestMatrix.Helper
{
    public class IOHelper
    {
        /// <summary>
        /// Read file content and return string
        /// UTF-8
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static string ReadFileToString(string path)
        {
            string fileString = null;

            if (string.IsNullOrWhiteSpace(path))
                return fileString;

            var fileUri = new Uri(path, UriKind.Relative);

            var fileStream = Application.GetResourceStream(fileUri);

            using (var reader = new StreamReader(fileStream.Stream, Encoding.UTF8))
            {
                try
                {
                    fileString = reader.ReadToEnd();
                    reader.Close();
                }
                catch
                {
                    return fileString;
                }
            }

            return fileString;
        }
    }
}
